package com.chess;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;

import android.os.Handler;
import android.os.Message;

public class ChessReaderThread extends Thread{

	private Socket socket;
	private BufferedReader reader;
	private Handler handler;
	
	public ChessReaderThread(Socket socket, Handler handler) {
		this.socket = socket;
		this.handler = handler;
		try {
			reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	@Override
	public void run() {
		while(true) {
			try {
				String receivedString = reader.readLine();
				Message msg = new Message();
				msg.what = 0x123;
				msg.obj = receivedString;
				handler.sendMessage(msg);
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

	
	
}
